<?php

/*
 * Edit by shengxin
 * Click nbfs://nbhost/SystemFileSystem/Templates/Scripting/PHPClass.php to edit this template
 */

namespace api\v1\controller;

use api\base\CRestBase;
use think\facade\Db;
/**
 * Description of AppController
 *
 * @author PC
 */
class AppsController extends CRestBase{
    public function firstBatchAddApp(){
        $data = $this->request->getContent();
        $obj = json_decode($data,true);
        $list = base64_decode($obj['listData']);
        $arr = json_decode($list,true);
        $time = time();
        //{"image":"","name":"浏览器","packageName":"com.android.browser","type":2,"brand":5}
        //[{"image":"","name":"浏览器","packageName":"com.android.browser","type":2,"brand":5}]
        foreach ($arr as $id => $app){
            $app['create_time'] = $time;
            $app['image'] = str_replace('.','',$app['packageName']).'.png';
            $arr[$id] = $app;
        }
        Db::name('applist')->insertAll($arr);
        $this->success('ok',[]);
    }
    public function batchAddApp(){
        $data = $this->request->getContent();
        $obj = json_decode($data,true);
        $list = base64_decode($obj['listData']);
        $arr = json_decode($list,true);
        $time = time();
        //[{"image":"","name":"浏览器","packageName":"com.android.browser","type":2,"brand":5}]
        foreach ($arr as $id => $app){
            $app['create_time'] = $time;
            $app['image'] = str_replace('.','',$app['packageName']).'.png';
            $arr[$id] = $app;
        }
        Db::name('applist')->insertAll($arr);
        $this->success('ok',[]);
    }
    /**
     * 获取临时解绑信息的方法
     * 
     * 本方法用于模拟获取某个学生临时解绑状态的信息。这些信息包括解绑的创建者、创建时间、是否被删除、
     * 解绑的生效和失效时间、解绑记录的ID、最后一次修改解绑信息的用户以及修改时间。
     * 对于学生而言，解绑状态可能与特定的功能或服务相关，例如临时取消绑定某个服务或权限。
     * 
     * @return array 返回一个包含临时解绑信息的数组，数组中包含了创建者、创建时间、删除状态、
     *               结束时间、ID、最后修改者、最后修改时间和开始时间。
     */
    public function getTemporaryUnBindInfo(){
        $data = [
            'createdBy' => 'admin',
            'createdDate' => '2021-08-01 09:09:09',
            'deleted' => false,
            'endTime' => '2021-08-01 09:09:09',
            'id' => '1',
            'lastModifiedBy' => 'admin',
            'lastModifiedDate' => '2021-08-01 09:09:09',
            'startTime' => '2021-08-01 09:09:09',
            'studentId' => '07d51f5d1577423ca1d82a570ee34fd9',
        ];
        return $this->success('ok',$data);
    }
}
